#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<cstdio>
using namespace std;

class MyTime
{
private:
	int hou;
	int min;
	int sec;

public:
	void setdata(int h, int m, int s)
	{
		hou = h;
		min = m;
		sec = s;
	}

	void print_12()
	{
		int h1 = hou;
		int count = 0;
		if (h1 > 12)
		{
			h1 -= 12;
			count++;
		}
		printf("%02d", h1);
		cout <<":" << min << ":" << sec;
		if (count == 1)
			cout << " PM" << endl;
		else
			cout << " AM" << endl;
	}

	void print_24()
	{
		cout <<hou <<":" << min <<":" << sec << endl;
	}
};

int main()
{
	int h;
	int m;
	int s;
	cin >> h >> m >> s;

	MyTime t1;
	t1.setdata(h, m, s);

	t1.print_12();
	t1.print_24();

	return 0;
}